const { app, BrowserWindow } = require('electron')
const path = require('path')

const createWindow = () => {
    console.log('Current NODE_ENV:', process.env.NODE_ENV) // 调试输出
    console.log('Electron version:', process.versions.electron) // 确认Electron环境
    console.log('Process arguments:', process.argv) // 确认启动参数

    const win = new BrowserWindow({
        width: 800,
        height: 600,
        webPreferences: {
            preload: path.join(__dirname, 'preload.js')
        }
    })

    if (process.env.NODE_ENV === 'development' || !app.isPackaged) {
        win.loadURL('http://localhost:5173')
        win.webContents.openDevTools()
    } else {
        win.loadFile(path.join(__dirname, '../dist/index.html'))
    }
}

app.whenReady().then(() => {
    createWindow()

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit()
})